package com.zingrow.web.configure.enshrine.service.impl;

import com.zingrow.web.base.service.impl.BaseService;
import com.zingrow.web.configure.enshrine.mapper.IEnshrineMapper;
import com.zingrow.web.configure.enshrine.model.Enshrine;
import com.zingrow.web.configure.enshrine.service.IEnshrineService;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EnshrineService extends BaseService<Enshrine> implements IEnshrineService {
    @Autowired
    private IEnshrineMapper ienshrineMapper;

    public boolean addEnshrine(String user_account, String ifm_id, String articleId,Date enshrine_time) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("user_account", user_account);
        map.put("ifm_id", ifm_id);
        map.put("articleId", articleId);
        map.put("enshrine_time", enshrine_time);
        return this.ienshrineMapper.addEnshrine(map) > 0;
    }

    public boolean deleteEnshrine(String user_account, String ifm_id, String articleId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("user_account", user_account);
//        map.put("ifm_id", ifm_id);
        map.put("articleId", articleId);
        return this.ienshrineMapper.deleteEnshrine(map) > 0;
    }

    public List<Enshrine> queryByUserAccount(String user_account) {
        return this.ienshrineMapper.queryByUserAccount(user_account);
    }

    public void initMapper() {
        this.baseMapper = this.ienshrineMapper;
    }

    @Override
    public List<Enshrine> queryByArticleIdAndUserAccount(String articleId,String user_account) {
        return ienshrineMapper.queryByArticleIdAndUserAccount(articleId,user_account);
    }
}
